package clang.control;

import clang.data.Expression;

public class WhileLoop implements CodeElement {
	
	private CodeBlock block = null;
	private Expression condition = null;
	
	public WhileLoop(CodeBlock block, Expression cond)
	{
		this.block = block;
		this.condition = cond;
	}
	
	@Override
	public void execute() throws Exception {
		if(block == null || condition == null) throw new Exception("Incomplete loop!");
		
		while(condition.calculate().getBool())
			block.execute();
	}

}
